package com.xqt.base.dao;



import com.xqt.base.page.BasePage;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.List;

public class BaseDao<T> {

	@Autowired
	@Qualifier("readSqlSession")
	private SqlSessionTemplate readSqlSession;

	@Autowired
	@Qualifier("writeSqlSession")
	private SqlSessionTemplate writeSqlSession;


	public T queryById(Object id){
		return readSqlSession.selectOne("read.sysmenu.queryById",id);
	}


	public int queryByCount(BasePage page){
		return readSqlSession.selectOne("read.sysmenu.queryByCount",page);
	}

	public void add(T object) {
		writeSqlSession.insert("write.sysmenu.update",object);
	}

	public void update(T object) {
		writeSqlSession.update("write.sysmenu.update",object);
	}

	public void updateBySelective(T object) {
		writeSqlSession.update("write.sysmenu.updateBySelective",object);
	}

	public void delete(Object id){
		writeSqlSession.delete("write.sysmenu.delete",id);
	}

	public List<T> queryByList(BasePage page) {
		return   readSqlSession.selectList("read.sysmenu.queryByList",page);
	}
}
